using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RetailAnalytic.Core;

namespace RetailAnalytic.Map.Engine
{
    public partial class FrmNPWizard : RetailAnalytic.Core.FrmNPWizardTemplate
    {
        PresentationBase presentationBase;
        ICrViewPropPresentation sp;
        public int iCurrPage = -1;
        public FrmNPWizard(PresentationBase PresentationBase)
        {
            presentationBase = PresentationBase;
            InitializeComponent();
            FirstWizardButtonNext();
        }
        public void FirstWizardButtonNext()
        {
            ultraGroupBox1.Enabled = false;
            sp = (ICrViewPropPresentation)new GUISupport(presentationBase, true);
            ultraGroupBox1.Enabled = true;
            iCurrPage++;
            SetCurrUC(iCurrPage);
        }
        private void FrmNPWizard_Load(object sender, EventArgs e)
        {
            SetCurrUC(iCurrPage);
        }
        public void SetCurrUC(int iUC)
        {
            UserControl currUC;
            PanelContainer.Controls.Clear();
            ubNext.Click -= delegate { FirstWizardButtonNext(); };
            currUC = sp.SelectCurrGuiParts(iUC);
            if (iUC < 4)
            {
                ubNext.Enabled = true;
                ubPrev.Enabled = true;
                ubCreate.Enabled = false;
            }
            else
            {
                ubNext.Enabled = false;
                ubPrev.Enabled = true;
                ubCreate.Enabled = true;
            }
            currUC.Dock = DockStyle.Fill;
            currUC.Parent = PanelContainer;
            currUC.Show();
        }
        public Int32 NewClassTaskID
        {
            get { return ((GUISupport)sp).presentationBase.ClassTaskID; }
        }

        #region Button
        private void ubNext_Click(object sender, EventArgs e)
        {
            if (iCurrPage > -1)
            {
                if (sp.TestCanSave(iCurrPage))
                {
                    iCurrPage++;
                    SetCurrUC(iCurrPage);
                }
            }
        }
        private void ubPrev_Click(object sender, EventArgs e)
        {
            if (iCurrPage == 0)
            {
                if (sp != null)
                {
                    sp.Cancel();
                }
            }
            iCurrPage--;
            if (iCurrPage == -1)
            {
                this.DialogResult = DialogResult.Abort;
                Close();
            }
            else
            {
                SetCurrUC(iCurrPage);
            }
        }
        private void Close_Wizard(object sender, EventArgs e)
        {
            if (sp == null)
                Close();
            else
            {
                if (sp.Cancel())
                    Close();
            }
        }
        private void ubCreate_Click(object sender, EventArgs e)
        {
            string ExtendStatusMessage;
            if (sp.TestCanSave(true, out ExtendStatusMessage))
            {
                if (sp != null)
                {
                    if (sp.Save())
                        this.DialogResult = DialogResult.OK;
                    Close();
                }
            }
        }
        #endregion Button
    }
}